//
//  StudentAcessView.m
//  HTT
//
//  Created by admin on 15/12/2.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "StudentAcessView.h"
#import "CourseRecordDetailModel.h"
@interface StudentAcessView()
@property (nonatomic, retain)CourseRecordDetailModel *courseRecordDetail;
@property (nonatomic, retain) NSMutableArray *btnArray;
@property (nonatomic, retain) UILabel *acessContentLabel;
@end
@implementation StudentAcessView

- (id)init{
    self = [super init];
    if (self) {
        [self _initView];
    }
    return self;
}
- (void)_initView{
    [self setBackgroundColor:[UIColor whiteColor]];
    _btnArray = [[NSMutableArray alloc] init];
    for (int i = 0 ; i < 5; i++) {
        UIButton *btn = [[UIButton alloc] init];
        [btn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateSelected];
        [btn setBackgroundImage:nil forState:UIControlStateNormal];
        [_btnArray addObject:btn];
    }
    
    _acessContentLabel = [self getNormolLabel];
    _acessContentLabel.textAlignment = _TEXT_ALIGN_LEFT;
    
}
- (void)setViewData:(id)viewData{
    _courseRecordDetail = viewData;
    [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj removeFromSuperview];
    }];
    if ([_courseRecordDetail.cgcStatus integerValue] == 2) {
        //教师完成课程
        if ([_courseRecordDetail.crAccess integerValue] == 0) {
            [self setFrame:CGRectMake(0, 0, 0, 0)];
        }else{
//            UILabel *titleLabel = [s]
            [self _initDetail];
        }
    }else{
        [self setFrame:CGRectMake(0, 0, 0, 0)];
    }
}
- (void)_initDetail{
    UILabel *titleLabel = [self getNormolLabel];
    titleLabel.font = [UIFont systemFontOfSize:20];
    titleLabel.text = @"课程评价";
    titleLabel.textAlignment = _TEXT_ALIGN_LEFT;
    [titleLabel setFrame:CGRectMake(10, 5, ScreenWidth - 20, 30)];
    [self addSubview:titleLabel];
    
    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(5, 40, ScreenWidth - 10, 1)];
    [line setBackgroundColor:RGBCOLOR(230, 230, 230, 1)];
    [self addSubview:line];
    
    UILabel *acessLabel = [self getNormolLabel];
    acessLabel.text = @"评价分数:";
    CGSize acessSize = [acessLabel.text textSizeWithFont:acessLabel.font constrainedSize:CGSizeMake(ScreenWidth, 100)];
    [acessLabel setFrame:CGRectMake(10, CGRectGetMaxY(line.frame) + 10, acessSize.width, acessSize.height)];
    [self addSubview:acessLabel];
    
    CGFloat x = CGRectGetMaxX(acessLabel.frame);
    
    [_btnArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (idx <= [_courseRecordDetail.crAccess integerValue] - 1) {
            UIButton *btn = (UIButton *)obj;
            [btn setImage:[UIImage imageNamed:@"star"] forState:UIControlStateNormal];
            [btn setFrame:CGRectMake(x+5 + idx * 25, CGRectGetMaxY(line.frame) + 5, 20, 20)];
            [self addSubview:btn];
        }
    }];
    
    [_acessContentLabel setText:[NSString stringWithFormat:@"评价内容: %@",_courseRecordDetail.crAccessContent]];
    acessSize = [_acessContentLabel.text textSizeWithFont:_acessContentLabel.font constrainedSize:CGSizeMake(ScreenWidth - 20, 20000)];
    [_acessContentLabel setFrame:CGRectMake(10, CGRectGetMaxY(acessLabel.frame) + 10, acessSize.width, acessSize.height)];
    [self addSubview:_acessContentLabel];
    [self setFrame:CGRectMake(0, 0, ScreenHeihgt, CGRectGetMaxY(_acessContentLabel.frame)+ 10)];
}
-(UILabel *)getNormolLabel{
    UILabel *label = [[UILabel alloc] init];
    label.textAlignment = _TEXT_ALIGN_CENTER;
    label.font = [UIFont systemFontOfSize:15];
    label.textColor = RGBCOLOR(0, 0, 0, 0.7);
    label.numberOfLines = 0;
    return label;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
